package com.ailk.cuc.autotestbg.startup;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import org.apache.commons.logging.Log;

import com.ailk.cuc.autotestbg.common.constants.StaticParam;
import com.ailk.cuc.autotestbg.common.utils.LogUtils;
import com.ailk.cuc.autotestbg.common.utils.ThreadPoolUtils;

public class ServerSocketThread extends Thread {

	private static Log logger = LogUtils.getLogger(ServerSocketThread.class.getName());
	@Override
	public void run() {

		ServerSocket server = null;
		Socket client = null;
		try {
			server = new ServerSocket(StaticParam.port);
			logger.info("开始监听端口 ： "+StaticParam.port);
			while(true){
				
				client = server.accept();
				logger.info("收到来自　："+client.getInetAddress().getHostName()+" 的连接");
				SocketProcesser processer = new SocketProcesser(client);
				logger.info("从线程池中，获取线程进行业务处理。。。");
				ThreadPoolUtils.execute(processer);
			}
		
			
		} catch (IOException e) {
			logger.error("SOCKETSERVER异常");
			logger.error(e.getMessage());
		}finally{
			try {
				ThreadPoolUtils.close();
				server.close();
			} catch (IOException e) {
				logger.error("关闭资源异常");
				logger.error(e.getMessage());
			}
		}
	
	}
}
